package testview.zhen.com.myapplication.jetpack

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Switch
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableField
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import testview.zhen.com.myapplication.R
import testview.zhen.com.myapplication.bean.Person
import testview.zhen.com.myapplication.databinding.ActivityDatabindingBinding


class DatabasingActivity : AppCompatActivity() , View.OnClickListener {

    var o =  ObservableArrayList<String>()

    lateinit var mactivityBinding: ActivityDatabindingBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //绑定布局
        mactivityBinding = DataBindingUtil.setContentView(this,R.layout.activity_databinding)
        o.add(0,"第一数据")
        mactivityBinding.peronInfo = Person("man",18,o)
        mactivityBinding.viewStub.viewStub!!.inflate()

        mactivityBinding.onClickListener = this
        mactivityBinding.list = o


//        var ft = supportFragmentManager.beginTransaction()
//        ft.add(mactivityBinding.frame.id,TestBindingFragment())
//        ft.commit()
    }

    override fun onClick(v: View?) {
        when(v){
            mactivityBinding.button7 -> {
                o.add(0,"第一数据")
                mactivityBinding.peronInfo = Person("man",19,o)
                mactivityBinding.peronInfo!!.Name = "qqqqqq"// = Person("man",19)
                mactivityBinding.title = "button7"
                o[0] = "button7"

               Thread(Runnable {
                   Thread.sleep(500)
                   Log.i("DatabasingActivity","Thread")
                   runOnUiThread {
                       Toast.makeText(this@DatabasingActivity,"打印一下子线程下的信息",Toast.LENGTH_SHORT).show()
                       mactivityBinding.title = "打印一下子线程下的信息"
                   }
               },"线程1").start()
            }
            mactivityBinding.button8 ->{
                mactivityBinding.peronInfo!!.Name = "hhhhhhhhhhhhhhhhh"
                mactivityBinding.title = "button8"
                o[0] = "button8"
                //= Person("man",20)
//                mactivityBinding.textView2.text = "这个是点击button8产生的"
            }
        }
    }
}
